package yingyong;

import gongju.DBUtil;
import packiging.Dept;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet("/add")
public class Add extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf8");
        resp.setContentType("text/html;character=utf8");
        String sql = "select * from Dept";
        try {
            ArrayList<Dept> list = new ArrayList<>();
            ResultSet re = DBUtil.qure(sql);
            while (re.next()){
                int deptID = re.getInt("DeptID");
                String deptName = re.getString("DeptName");
                Dept dept = new Dept(deptID, deptName);
                list.add(dept);
            }
            req.setAttribute("list",list);
            req.getRequestDispatcher("WEB-INF/xianshi.jsp").forward(req,resp);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }
}
